import os
from multiprocessing import Pool, cpu_count
from multiprocessing.pool import ThreadPool
import math
import datetime
from tqdm import tqdm
import time, random

def func(num):
    name=num
    with tqdm(range(5), ncols=80, desc='执行任务' + str(name) + ' pid:' + str(os.getpid())) as pbar:
        for i in range(5):#time.sleep(random.random() * 3)
            time.sleep(1)
            print("finished")
            pbar.update()
            print("cpu_count():",cpu_count())

    pool= Pool(10)
    start=time.time()
    with tqdm(total=50) as pbar:
        for i in (range(50)):
            pool.apply_async(func, args=(i,))
            pool.close()
            pool.join()

    end=time.time()
    print("\n应用多进程耗时: %0.2f seconds" % (end -start))
    print("over")

if __name__ == '__main__':
    func(10)